﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Insteon.Messages
{
    //receives bytes and returns a message when one is detected.
    internal static class MessageFactory
    {
        private static UInt64 Number = 0;

        internal static Message Create(byte[] buffer, UInt16 Length, out UInt16 Size)
        {
            Size = 0;
            if (buffer[0] != 2)
            {
                //we have a problem
            }
            if (Insteon.StandardResponse.Check(buffer, Length))
            {
                return new Insteon.StandardResponse(buffer, Length, ++Number, out Size);
            }
            if (Insteon.StandardMessage.Check(buffer, Length))
            {
                return new Insteon.StandardMessage(buffer, Length, ++Number, out Size);
            }
            if (Insteon.ExtendedMessage.Check(buffer, Length))
            {
                return new Insteon.ExtendedMessage(buffer, Length, ++Number, out Size);
            }
            if (Insteon.StartAllLinkResponse.Check(buffer, Length)){
                return new Insteon.StartAllLinkResponse(buffer, Length, ++Number, out Size);
            }
            if (Insteon.AllLinkResponse.Check(buffer, Length))
            {
                return new Insteon.AllLinkResponse(buffer, Length, ++Number, out Size);
            }
            if (Insteon.AllLinkCleanupMessage.Check(buffer, Length))
            {
                return new Insteon.AllLinkCleanupMessage(buffer, Length, ++Number, out Size);
            }
            if (Insteon.AllLinkingCompletedMessage.Check(buffer, Length))
            {
                return new Insteon.AllLinkingCompletedMessage(buffer, Length, ++Number, out Size);
            }
            if (Insteon.ButtonEventReportMessage.Check(buffer, Length))
            {
                return new Insteon.ButtonEventReportMessage(buffer, Length, ++Number, out Size);
            }
            return null;
        }
    }
}
